package cn.lili.modules.system.serviceimpl;


import cn.lili.modules.system.mapper.SupplyChainMapper;
import cn.lili.modules.system.service.SupplyChainService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.lili.modules.system.entity.dos.SupplyChain;
import groovy.util.logging.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class SupplyChainServiceImpl extends ServiceImpl<SupplyChainMapper,SupplyChain> implements SupplyChainService {


    @Override
    public List<SupplyChain> getOpenSupplyChains() {
        QueryWrapper<SupplyChain> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","name","short_name");
        queryWrapper.lambda().eq(SupplyChain::getStatus,1);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public Integer updateStatus(String id, Integer status) {
        LambdaUpdateWrapper<SupplyChain> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(SupplyChain::getStatus,status);
        updateWrapper.eq(SupplyChain::getId,id);
        return this.baseMapper.update(null,updateWrapper);

    }

    @Override
    public List<SupplyChain> listBy(String[] fields, List<String> idList) {
        QueryWrapper<SupplyChain> queryWrapper = new QueryWrapper<>();
        queryWrapper.select(fields);
        queryWrapper.lambda().in(SupplyChain::getId,idList);
        return this.baseMapper.selectList(queryWrapper);
    }
}
